6/**
 * 银行收支日结报表管理初始化
 */
var Expenditure = {
    id: "ExpenditureTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
   // clickToSelect: false,
};

/**
 * 初始化表格的列
 */
Expenditure.initColumn = function () {
    return [

        [

		 {field: 'selectItem', radio: true,colspan: 1,rowspan: 2,width:'36px'},
            {
                field: 'revdate',
                title: "日期",
                valign:"middle",
                align:"center",
                colspan: 1,
                rowspan: 2,
				formatter:function(value,row,index){
                    if(value==null||value==''){return '上期余额';}else{ return value.substring(0,10);}

				}
			,colspan: 1,rowspan: 2},
            {
                title: "收入",
                valign:"middle",
                align:"center",
                colspan: 3,
                rowspan: 1
            },
            {
                title: "支出",
                valign:"middle",
                align:"center",
                colspan: 4,
                rowspan: 1
            },

            {
                field: 'netIncomeOfBanks',
                title: "银行第三方净收入",
                halign:"center",
                valign:"middle",
                align:"right",
                colspan: 1,
                rowspan: 2
            },
            {
                field: 'totalBankBalance',
                title: "银行与第三方总余额",
                halign :"center",
                valign:"middle",
                align:"right",
                colspan: 1,
                rowspan: 2
            }

        ],
        [
            {
                field: 'recharge',
                title: "客户充值",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'otherDeposits',
                title: "其他入款",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'totalBankDeposits',
                title: "银行总入款",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'reflect',
                title: "客户提现",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'fee',
                title: "手续费",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'otherWithdrawals',
                title: "其他支出",
                halign :"center",
                valign:"middle",
                align:"right"
            },
            {
                field: 'totalBankWithdrawal',
                title: "银行总出款",
                halign :"center",
                valign:"middle",
                align:"right"
            }

        ]



    ];
};

/**
 * 检查是否选中
 */
Expenditure.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        Expenditure.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加银行收支日结报表
 */
Expenditure.openAddExpenditure = function () {
    var index = layer.open({
        type: 2,
        title: '添加银行收支日结报表',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/expenditure/expenditure_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看银行收支日结报表详情
 */
Expenditure.openExpenditureDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '银行收支日结报表详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/expenditure/expenditure_update/' + Expenditure.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除银行收支日结报表
 */
Expenditure.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/expenditure/delete", function (data) {
            Feng.success("删除成功!");
            Expenditure.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("expenditureId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Expenditure.formParams = function() {
    var queryData = {};
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();
	queryData['platform'] = $("#platform").val();
    return queryData;
}

/**
 * 查询银行收支日结报表列表
 */
Expenditure.search = function () {
    Expenditure.table.refresh({query: Expenditure.formParams()});
	$("#ExpenditureSum").remove();
    $("#ExpenditureTable").after(  Expenditure.tatol()   )
};


/**
 * 打开导出页面
 */
Expenditure.operExport = function(){
    window.location.href = "/expenditure/exportExpenditure?beginTime=" + $("#beginTime").val()+"&endTime="+$("#endTime").val();
}


Expenditure.resetSearch = function () {
    $("#beginTime").val("");
    $("#endTime").val("");
}

Expenditure.tatol= function(){
	
	var tatol;
    var ajax = new $ax(Feng.ctxPath + "/expenditure/tatol", function (result) {
        tatol=result;
    }, function (result) {
        Feng.error("查询失败!" + result.responseJSON.message + "!");
    });
    ajax.setData(Expenditure.formParams());
    ajax.start();

 /*var rowTem = '<div id="ExpenditureSum" class="alert  alert-dismissable" style="font-size: medium;color: #1f1d1e;background-color: #e4d6cc;border-color: #8392d7;">'
	+"总计: 客户充值:"+tatol.recharge+" ,其他入款:"+tatol.otherDeposits+" ,银行总入款:"+tatol.totalBankDeposits+" ,客户提现:"+tatol.reflect
	+" ,手续费:"+tatol.fee+" <br>其他支出:"+tatol.otherWithdrawals+" ,银行总出款:"+tatol.totalBankWithdrawal+" ,银行第三方净收入:"+tatol.netIncomeOfBanks+" ,银行与第三方总余额:"+tatol.totalBankBalance
	+'</div>';*/

    var rowTem = '<div><table id="ExpenditureSum" data-mobile-responsive="true" data-click-to-select="false" class="table table-hover table-striped" style="margin-top: -0px;color: #2A2E36;font-size: 14px;"><tbody id="ExpenditureSum" >'+
        '<tr data-index="0">'+
        '<td style="text-align: center; vertical-align: middle; width:122%;">总计：</td> '+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.recharge+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.otherDeposits+'</td> '+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.totalBankDeposits+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.reflect+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.fee+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.otherWithdrawals+'</td>'+
        '<td style="text-align: right; vertical-align: middle; ">'+tatol.totalBankWithdrawal+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.netIncomeOfBanks+'</td>'+
        '<td style="text-align: right; vertical-align: middle;">'+tatol.totalBankBalance+'</td>'
        '</tr></tbody></table></div>';
	
    return rowTem;
}

$(function () {
    var defaultColunms = Expenditure.initColumn();
    var table = new BSTable(Expenditure.id, "/expenditure/list", defaultColunms,Expenditure);
    table.height=750;
	table.setPaginationType("server");
	table.setShowColumns(false);
	table.setShowRefresh(false);
    table.setQueryParams(Expenditure.formParams());
    Expenditure.table = table.init();
	//添加表头
	$(".fixed-table-toolbar").after("<div style='text-align: center;vertical-align: middle;font-size: 22px;color: #6979d7;font-weight: bold;'> 银行收支日报表</div>");
	$("#ExpenditureTable").after(Expenditure.tatol());
});
